package com.project.imageinterference.controller;

import com.project.imageinterference.dto.response.NewsRes;
import com.project.imageinterference.exception.BusinessException;
import com.project.imageinterference.service.NewsService;
import com.project.imageinterference.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 新闻表 前端控制器
 * </p>
 *
 * @author haochuanwan
 * @since 2025-02-22
 */
@Api(tags = "新闻接口")
@RestController
@RequestMapping("/news")
public class NewsController {

    @Resource
    private NewsService newsService;

    @ApiOperation(value = "查询新闻详情")
    @GetMapping(value = "defaultNews")
    public Result<NewsRes> getDefaultNews(){
        try {
            NewsRes newsInfo = newsService.getDefaultNews();
            return Result.success(newsInfo);
        }catch (BusinessException e) {
            return Result.failure(e.getMessage());
        } catch (Exception e) {
            return Result.failure("查询失败: " + e.getMessage());
        }
    }
}
